using UnityEngine;
using System.Collections;

public class BomberScript : MonoBehaviour {
	
	public float speed;
	public Rigidbody bomb;
	public Transform target;
	public float interval = 0.5f;
	public float lastShot = -10.0f;
	private float m_interval;

	// Use this for initialization
	void Start () {
		target = GameObject.FindWithTag("Player").transform; 
	
	}
	
	// Update is called once per frame
	void Update () {
		transform.Translate(speed,0,0);
		m_interval = Random.Range(interval/2, interval);
		Vector2 down = transform.TransformDirection (-Vector2.up);
		RaycastHit hit;
		
		if (Physics.Raycast(transform.position, down, out hit, 20)){
			if(Time.time > m_interval + lastShot){		
				Rigidbody instance = Instantiate(bomb, transform.position,transform.rotation) as Rigidbody;
				Destroy(instance.gameObject, 2);
				lastShot = Time.time;
			}
		}
			
	
	}
}
